import { PureComponent } from 'react';
import showHide from '@wpt/showHide';

@showHide
export default class ScrollFixer extends PureComponent {
    componentDidMount() {
        this.onPageShow();
    }

    componentWillUnmount() {
        this.onPageHide();
    }

    onPageShow() {
        this.overflowHidden();
    }

    onPageHide() {
        this.overflowHidden(false);
    }

    overflowHidden(hidden = true) {
        const { disableSelector } = this.props;
        if (disableSelector) {
            return;
        }
        $(document.body).css({ overflow: hidden ? 'hidden' : '' });
    }

    render() {
        return this.props.children;
    }
}
